﻿using System.Collections.Generic;
using System.Linq;

namespace Inscriptionem.Areas.Inscriptionem.Models.Views
{
    public class PostSearchCollectionViewModel
    {
        public IEnumerable<ORM.Post> Posts { get; protected set; }

        public PostSearchCollectionViewModel()
        {
            Posts = new ORM.DB().Posts.Where(p => p.Title.ToLower().Contains(Text.ToLower()) || p.Content.ToLower().Contains(Text.ToLower()))
                .OrderBy(p => p.PostCategories.Select(pc => pc.Category).FirstOrDefault().ID)
                .ThenBy(p => p.PostCategories.Select(pc => pc.Category).FirstOrDefault().Section.ID)
                .ThenBy(p => p.PostCategories.Select(pc => pc.Category).FirstOrDefault().Section.Language.ID).ThenByDescending(p => p.ID);
        }

        public string Text { get; set; }
        public int Page { get; set; }
    }
}